﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace XNAFight.Engine.Inputs
{
    public class Controler
    {
        private PlayerIndex index;
        private InputType type;

        public PlayerIndex Index
        {
            get { return index; }
            set { index = value; }
        }
        public InputType Type
        {
            get { return type; }
            set { type = value; }
        }
        
        public Controler()
        {}

        public Controler(InputType _type, PlayerIndex _index = PlayerIndex.One)
        {
            type = _type;
            index = _index;
        }

        public override string ToString()
        {
            if (this.type == InputType.Keyboard)
                return this.type.ToString();
            else
                return this.type.ToString() + " " + this.index.ToString();
        }

        // overload operator ==
        public static bool operator ==(Controler a, Controler b)
        {
            // If both are null, or both are same instance, return true.
            if (System.Object.ReferenceEquals(a, b))
            {
                return true;
            }

            // If one is null, but not both, return false.
            if (((object)a == null) || ((object)b == null))
            {
                return false;
            }

            // Sinon on compare le type et l'index
            if (a.Type == InputType.Keyboard)
                return a.Type == b.Type;
            else
                return (a.Type == b.Type) && (a.Index == b.Index);
        }
        // overload operator !=
        public static bool operator !=(Controler a, Controler b)
        {
            return !(a == b);
        }
    }
}
